#define  _CRT_SECURE_NO_WARNINGS 1
#include"Date.h"
bool Date::operator>(const Date& d)const {
	if (_year > d._year) {
		return true;
	}
	if (_year == d._year && _month > d._month) {
		return true;
	}
	if (_year == d._year && _month == d._month && _day > d._day) {
		return true;
	}

	return false;
}
bool Date::operator<(const Date& d)const {

	return !(*this >= d);
}
bool Date::operator>=(const Date& d) const {

	return *this > d || *this == d;

}
bool Date::operator<=(const Date& d)const {
	return !(*this > d);
}
bool Date::operator==(const Date& d)const {

	return _year == d._year && _month == d._month && _day == d._day;

}
bool Date::operator!=(const Date& d)const {


	return !(*this == d);
}
Date::Date(int a, int b, int c)  {
	_year = a;
	_month = b;
	_day = c;

}
int Date::GetDay(int year, int month)  {
	assert(month > 0 && month < 13);
	static int arr[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if (month == 2 && ((year % 4 == 0 && year % 100 != 0)
		|| (year % 400 == 0))) {

		return 29;
	}
	return arr[month]; 
}
Date& Date::operator+=(int n){
	_day += n;

	while (_day > GetDay(_year, _month))  {
		_day -= GetDay(_year, _month);
		_month++;
		if (_month == 13) {
			_year++;
			_month = 1;
		}

	}

	return *this;

}
Date Date::operator+(int n)const {


	Date tem = *this;
	tem += n;
	return tem;


}
Date& Date::operator-=(int n) {
	_day = _day - n;
	while (_day <= 0) {

		_month--;
		if (_month == 0) {

			_month = 12;
			_year--;

		}
		_day += GetDay(_year, _month);



	}
	return *this;



}
Date Date::operator-(int n)const {

	Date tem = *this;
	tem -= n;
	return tem;
}

void Date::Print()const {
	cout << _year << " " << _month << " " << _day << endl;


}